package dialogs
{
	import Classes.pi_events;
	
	import UIFree.ObjectEvent;
	import UIFree.components.uif_window;
	import UIFree.controls.uif_baseCheckBox;
	import UIFree.controls.uif_checkbox;
	import UIFree.controls.uif_input;
	import UIFree.controls.uif_label;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import components.pj_button;
	
	import flash.events.Event;
	import flash.geom.Rectangle;	

	public class pi_payDialog extends uif_window {
		private var _otherPrice: uif_label;
		private var sms_box: uif_ecomponent;
		public static var smsTypes: Object	= {}
		
		public function pi_payDialog(parent:uif_component, postPayProc: Function=null) {
			super(parent, 0, 0, 320, 270, 'window', true);
			title.text = pi_data.PAYDIALOGTITLE;
			toCenter(app);
			var inner: Rectangle = getInner();
			var button: uif_label;
			
			button = new pj_button(this, inner.x + inner.width - 120, height - pj_button.HEIGHT, 120, pi_data.INVITECAPTION, function(e: Event): void {
				doClose(null);
				app.dispatchEvent(new Event(pi_events.INVITEDIALOG));
			});
			
			button = new pj_button(this, button.x - 80, height - pj_button.HEIGHT, 80, 'Пополнить', function(e: Event): void {
				e.target.disable = true;
				doClose(null);
				var _curSMS: int = (sms_box.getChildAt(1) as uif_baseCheckBox).checkedIndex;
				var payParams: Object = {
					sms_price	: (_curSMS * 2) + 1, 
					other_price	: smsTypes[_curSMS + 1].value,
					postPay		: postPayProc
				}
				app.dispatchEvent(new ObjectEvent(pi_events.STARTPAYMENT, payParams));				
			});
			
			with (new uif_label(this, inner.x, 0, inner.width, 123, 'description')) {
				htmlText = 'Пополнить баланс вы можете при помощи СМС-платежа или используя одну из предлагаемых платежные систем.\nА так же <b>вы получите</b> ' + pj.siteData.INVITEDESC;
				alignApply(['left', 'top']);
			}

/*			_otherPrice = (new uif_label(this, 140, 175, 80, 20, 'minput'));
			_otherPrice.text = '0';*/
			
			sms_box = new uif_ecomponent(this, 0, 135, inner.width, 60, 'white');

			with (new uif_label(sms_box, 35, 0, inner.width - 35, 20, 'lbLabel')) {
				text = 'Выберите сумму';
			}
			
/*			sms_box.addEvent(uif_baseCheckBox.CHECKED, function(e: Event): void {
				_otherPrice.text = '0';
				_curSMS = (e.target as uif_component)._data;
				e.stopPropagation();
			});*/
			
			var i:int = 0;
			for each (var sms: Object in smsTypes) {
				var by: int = 25 + i * 20;
				
				var cbButton: uif_checkbox = new uif_checkbox(sms_box, 20, by, 80, 20, 'chButton');
				cbButton.text = sms.value + ' руб.';
//				cbButton._data = sms.id;
				if (i == 1) cbButton.checked = true; 

/*				var _label: uif_label = new uif_label(sms_box, 50, by, 60, 20, 'collection');
				_label.text = sms.name;
				button = new uif_button(sms_box, 35, by + 4, 10, 10, 'collectButton');
				_smsButton[sms.id] = button;
				button._data = sms.id;
				button.addEventListener(MouseEvent.CLICK, function(e: MouseEvent): void {
					selectSMS((e.target as uif_button)._data);
				});*/
				i++;
			}
/*			
			_otherPrice.textField.addEventListener(Event.CHANGE, function(e: Event): void {
				var value: Number = parseFloat(_otherPrice.textField.text);
				if (value > 0) sms_box.fx('alpha', sms_box.alpha, 0.5).start();
				else sms_box.fx('alpha', sms_box.alpha, 1).start();
			});*/
		}
		
		public function get pj(): photo_inject {
			return app as photo_inject;
		}
	}
}